<?php


class Zender_Config_Db_Table extends Zend_Db_Table_Abstract {
	
	protected $_name = 'configs';
	protected $_sequence = false;
	
	/**
	 * Overload del metodo standard per impostare il nome del db preceduto dal prefisso
	 *
	 */
	protected function _setupTableName() {
		
		$_prefix = "";
		
		try {
			$_prefix = Zender_Registry::get('configs.ini')->main->db->system->tableprefix;
		} catch (Exception $e) {
			/**
			 * @todo Error Stream for debug
			 */
		}
		$this->_name = $_prefix . $this->_name; 
		parent::_setupTableName();
		
	}
	/**
	 * Read all configs from db and convert them in a array of key -> value
	 *
	 * @return array configs converted
	 */
	public function getConfigsAsArray() {
		
		$fetched = $this->fetchAll();
		$dataArray = array();
		while ( $fetched->valid() ) {
			$config = $fetched->current();
			$dataArray[$config->name] = $config->value;
			$fetched->next();
		}
		return $dataArray;
	}
}